//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using CommunityServer.ControlPanel.Controls.Galleries;
using CommunityServer.ControlPanel.UI;
using CommunityServer.Controls;
using CommunityServer.Galleries.Components;
using ResourceLinkButton = CommunityServer.ControlPanel.Controls.ResourceLinkButton;
using ResourceControl = CommunityServer.ControlPanel.Controls.ResourceControl;
using StatusMessage = CommunityServer.ControlPanel.Controls.StatusMessage;

namespace CommunityServer.ControlPanel.Photos.Options
{
	/// <summary>
	/// Summary description for SkinsOptionsPage.
	/// </summary>
	public class SkinsOptionsPage : BaseGalleryPage
	{

		#region Child Controls

		protected SkinOptionsControl Skin1;
		protected SkinOptionsCSSControl CSS1;
		protected MPContent DescriptionRegion;
		protected MPContent TaskRegion;
		protected MPContainer MPContainer;
		protected Script Script1;
		protected Script Script2;
		protected ResourceLinkButton SaveButton;
		protected ResourceControl Resourcecontrol1;
		protected ResourceControl Resourcecontrol2;
		protected StatusMessage Status;
		protected SkinOptionsLayoutControl Layout1;

		#endregion

		private void Page_Load(object sender, EventArgs e)
		{
			if(!IsPostBack)
			{
				Skin1.Gallery = CSS1.Gallery = Layout1.Gallery = CurrentGallery;
			}
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
			this.SaveButton.Click += new EventHandler(SaveButton_Click);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

        private void SaveButton_Click(object sender, EventArgs e)
        {
            if(Page.IsValid && GalleryConfiguration.Instance().EnableThemes)
            {
				Skin1.GetFormValues(CurrentGallery); 
				CSS1.GetFormValues(CurrentGallery); 
				Layout1.GetFormValues(CurrentGallery); 
				
            	CommunityServer.Galleries.Galleries.Update(CurrentGallery);

				Skin1.SetSelectedTheme(CurrentGallery) ;

				Status.Success = true;
				Status.Text = "Your changes have been saved successfully";
				Status.Visible = true;
			}
        }
    }
}
